package cn.snorlaxzjt.LBSserver.controller;

import cn.snorlaxzjt.LBSserver.common.BusinessCode;
import cn.snorlaxzjt.LBSserver.common.Result;
import cn.snorlaxzjt.LBSserver.po.page.ChatInfoPage;
import cn.snorlaxzjt.LBSserver.push.CimMessagePusher;
import cn.snorlaxzjt.LBSserver.service.MessageService;
import com.farsunset.cim.sdk.server.model.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/message")
public class MessageController {
    @Autowired
    MessageService messageService;
    @Resource
    private CimMessagePusher defaultMessagePusher;

    @PostMapping(value = "/send")
    public Result<Integer> send(@RequestBody Message message) {
        defaultMessagePusher.push(message);
        return BusinessCode.SUCCESS.toResult();
    }

    @PostMapping("/get")
    public Result<List<cn.snorlaxzjt.LBSserver.po.entity.Message>> getMessage(@RequestParam String receiverId) {
        List<cn.snorlaxzjt.LBSserver.po.entity.Message> message = messageService.getMessage(Integer.valueOf(receiverId));
        return  BusinessCode.SUCCESS.toResult(message);
    }
    
    @PostMapping("/list")
    public  Result<List<ChatInfoPage>> getChatList(){
        List<ChatInfoPage> list = messageService.getList();
        return  BusinessCode.SUCCESS.toResult(list);
    }
}